package com.lightsh.viewpager;

import java.util.ArrayList;

import com.viewpagerindicator.TitleProvider;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class MyPagerAdapter extends FragmentPagerAdapter implements TitleProvider{

	private ArrayList<? extends Fragment> mFragments;
	private ArrayList<String> mTitle;
	
	public MyPagerAdapter(FragmentManager fm, ArrayList<? extends Fragment> fragments, ArrayList<String> titles) {
		super(fm);
		mFragments = fragments;
		mTitle = titles;
		if(mFragments.size() != mTitle.size()){
			throw new IllegalArgumentException("fragment size must equal title size!");
		}
	}

	@Override
	public Fragment getItem(int position) {
		return mFragments.get(position);
	}

	@Override
	public int getCount() {
		return mFragments.size();
	}

	@Override
	public String getTitle(int position) {
		return mTitle.get(position);
	}

}
